package com.airnews.ticket.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.airnews.ticket.R;
import com.airnews.ticket.adapter.GridAdapter;
import com.airnews.ticket.ui.flight.FlightList;
import com.airnews.ticket.ui.flight.FlightQuery;
import com.airnews.ticket.util.Constants;
import com.airnews.ticket.util.Utils;

/**
 * 主页面
 */
public class Main extends BaseActivity{
	
	private GridView gridView;
	private GridAdapter gridAdapter;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		gridView = (GridView)findViewById(R.id.gridView);
		gridAdapter = new GridAdapter(this, Constants.MAIN_MENU_LIST);
		gridView.setAdapter(gridAdapter);
		gridView.setOnItemClickListener(onItemClickListener);
	}

	
	
	private OnItemClickListener onItemClickListener = new OnItemClickListener(){
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			switch(view.getId()){
				case R.drawable.icon_flight:{//航班查询
					Intent it = new Intent(Main.this, FlightQuery.class);
					startActivity(it);
					break;
				}
				case R.drawable.icon_login:{//登陆
					Intent it = new Intent(Main.this, Login.class);
					it.putExtra(Constants.CLASS_NAME, FlightList.class.getName());
					startActivity(it);
					break;
				}
			}
			
		}
	};
	
	@Override
	public void onBackPressed() {
		Utils.exitAppDialog(this);
	}

}